import request from '@/utils/request'
import wx from 'weixin-js-sdk'

export const getDateApi = (data) => {
  return request({
    url: '/getDepOrdersInfo',
    method: 'POST',
    data
  })
}

// 获取验证码
export const getVerifyCodeApi = (data) => {
  return request({
    url: '/getSmsCode',
    method: 'POST',
    data
  })
}

// 登录
export const loginApi = (data) => {
  return request({
    url: '/login',
    method: 'POST',
    data
  })
}

// 获取监控列表
export const getCameraListApi = (data) => {
  return request({
    url: '/getStreamLists',
    method: 'POST',
    data
  })
}

// // 获取监控页面凭证
// export const getCameraTokenApi = (data) => {
//   return request({
//     url: '/getUUID',
//     method: 'POST',
//     data
//   })
// }

// // 开启直播
// export const startLiveApi = (data) => {
//   return request({
//     url: '/startLive',
//     method: 'POST',
//     data
//   })
// }

// // 关闭直播 页面退出
// export const stopLiveApi = (data) => {
//   return request({
//     url: '/closePage',
//     method: 'POST',
//     data
//   })
// }

// 获取微信签名信息
export const getWeixinSignApi = (jsApiList) => {
  request({
    url: 'https://www.mahelei.com/index.php/Gm/Wechat/share',
    method: 'POST',
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    data: {
      url: encodeURIComponent(window.location.href.split('#')[0])
    }
  }).then((res) => {
    weixinInit(res, jsApiList)
  })
}

// 微信配置
const weixinInit = (e, jsApiList) => {
  const data = e.data
  wx.config({
    debug: false,
    appId: data.appId,
    timestamp: data.timestamp,
    nonceStr: data.nonceStr,
    signature: data.signature,
    jsApiList
  })
  wx.ready(() => {
    wx.checkJsApi({
      jsApiList,
      success: (res) => {
        console.log(res)
      }
    })
  })
}
